const { centerClick, coordinateClick } = require("../common");
auto.waitFor();
const appName = "百度极速版";
launchApp(appName);
sleep(2000);
goTask();

function goTask() {
  centerClick(id("aj0"));
  sleep(2000);
  centerClick(className("android.view.View").text("问题反馈"))
  centerClick(className("android.view.View").text("去签到"));
  watchAD()
//   happyAccept();
//   openBox();
}


// 开箱赚金币 aw6 am5
function openBox() {
  const btn = className("android.view.View").text("开宝箱得金币");
  if (btn.exists()) {
    centerClick(btn);
    sleep(1500);
    centerClick(className("android.view.View").textContains("观看视频再得"));
    sleep(20000);
    closeAD();
    sleep(2000);
    openBox();
  }
}

function closeAD() {
  coordinateClick(948, 113, 1065, 230);
  sleep(1500);
  const btn1 = className("android.widget.TextView").textContains(
    "再看一个领取"
  );
  const btn2 = className("android.view.View").textContains("看广告再得");
  const btn3 = className("android.view.View").textContains("立即收下");
  if (btn1.exists()) {
    centerClick(btn1);
    sleep(20000);
    closeAD();
  }
  if (btn2.exists()) {
    centerClick(btn2);
    sleep(20000);
    closeAD();
  }
  if (btn3.exists()) {
    centerClick(btn2);
  }
}

function happyAccept() {
  centerClick(className("android.view.View").text("开心收下"));
}

function watchAD(){
    id("app").findOne().children()
    .forEach(function(child){
        log(child.className());
        log(child.childCount())
    });
    const box=className("android.view.View").depth(17).indexInParent(5)
  
}
